package models

import (
	"hippo/hipporpc/hipporpc"

	"gorm.io/gorm"
)

type Shop struct {
	gorm.Model
	Title   string  `gorm:"type:varchar(30);not null;"`
	Price   float64 `gorm:"type:decimal(10,2);not null;"`
	Info    string  `gorm:"type:varchar(300);not null;"`
	Num     int     `gorm:"type:int(10);not null;"`
	ClassId int     `gorm:"type:int(10);not null;"`
}

type Class struct {
	gorm.Model
	Title string `gorm:"type:varchar(30);not null;"`
}

func (s *Shop) ShopAdd(db *gorm.DB) error {
	return db.Debug().Create(s).Error
}

func (s *Shop) ShopList(db *gorm.DB) ([]*hipporpc.ShopList, error) {
	var shops []*hipporpc.ShopList

	err2 := db.Debug().Model(&Shop{}).
		Select(
			"shops.id as shop_id",
			"shops.title",
			"shops.price",
			"shops.info",
			"shops.num",
			"shops.class_id",
		).Find(&shops).Error

	return shops, err2
}
